# jsb/lib/cleaner.py
#
#

""" cleaner module. """

## jsb imports

from jsb.lib.periodical import minutely

## basic imports

import logging

## Cleaner class

class Cleaner(object):

    def __init__(self):
        self.clean = []

    def register(self, obj):
        if obj not in self.clean: self.clean.append(obj) ; logging.warn("registered %s" % str(obj))

    def unregister(self, obj):
        try: self.clean.remove(obj) ; return True
        except ValueError: return False

    @minutely
    def doclean(self):
        for toclean in self.clean:
            toclean.cleanup()

## cleaner object

cleaner = Cleaner()
